package com.guaoran.interview.in2018.serialize;

import com.guaoran.interview.in2018.bean.User;

import java.io.*;

/**
 * @author : guaoran
 * @Description : <br/>
 *  java api 原生序列化
 * @date :2018/12/21 14:04
 */
public class SerialDemo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        User user = new User("guaoran",18);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream outputStream = new ObjectOutputStream(byteArrayOutputStream);
        outputStream.writeObject(user);
        byte[] arr = byteArrayOutputStream.toByteArray();

        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(arr);
        ObjectInputStream inputStream = new ObjectInputStream(byteArrayInputStream);
        User u = (User) inputStream.readObject();
        System.out.println(u);
        //        FileOutputStream fileOutputStream = new FileOutputStream()

    }
}
